using System;
using System.Collections;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.Base.Exceptions;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Util;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for UIGridColumnInfo objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for UIGridColumnInfo.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestUIGridColumnInfo
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }


        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            UIGridColumnInfo uiGridColumn = TestUtilsUIGridColumnInfo.CreateUnsavedValidUIColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiGridColumn.UIGrid);
            Assert.IsNotNull(uiGridColumn.PropertyName);
            //---------------Execute Test ----------------------
            string actualToString = uiGridColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(uiGridColumn.UIGrid + " - " + uiGridColumn.PropertyName, actualToString);
        }

        [Test]
        public void Test_ToString_UIGridNull()
        {
            //---------------Set up test pack-------------------
            UIGridColumnInfo uiGridColumn = TestUtilsUIGridColumnInfo.CreateUnsavedValidUIColumn_WNullGrid();
            //---------------Assert Precondition----------------
            Assert.IsNull(uiGridColumn.UIGrid);
            TestUtilsShared.AssertStringNotEmpty(uiGridColumn.PropertyName, "uiGridColumn.PropertyName");
            //---------------Execute Test ----------------------
            string actualToString = uiGridColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(" - " + uiGridColumn.PropertyName, actualToString);
        }

        [Test]
        public void Test_ToString_UIGridNull_PropertyNull()
        {
            //---------------Set up test pack-------------------
            UIGridColumnInfo uiGridColumn = TestUtilsUIGridColumnInfo.CreateUnsavedValidUIColumn_WNullGrid_NullProperty
                ();
//            uiGridColumn.PropertyName = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiGridColumn.UIGrid);
            Assert.IsNull(uiGridColumn.PropertyName);
//            AssertStringEmpty("uiGridColumn.PropertyName", uiGridColumn.PropertyName);
            //---------------Execute Test ----------------------
            string actualToString = uiGridColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(uiGridColumn.UIPropID.ToString(), actualToString);
        }

//        [Test]
//        public void Test_ToString_UIGridNull_PropertyEmpty()
//        {
//            //---------------Set up test pack-------------------
//            UIGridColumnInfo uiGridColumn = TestUtilsUIGridColumnInfo.CreateUnsavedValidUIColumn_WNullGrid();
//            uiGridColumn.PropertyName = "";
//            //---------------Assert Precondition----------------
//            Assert.IsNull(uiGridColumn.UIGrid);
//            AssertStringEmpty("uiGridColumn.PropertyName", uiGridColumn.PropertyName);
//            Assert.IsNotNull(uiGridColumn.UIPropID);
//            //---------------Execute Test ----------------------
//            string actualToString = uiGridColumn.ToString();
//            //---------------Test Result -----------------------
//            Assert.AreEqual(uiGridColumn.UIPropID.ToString(), actualToString);
//        }

        [Test]
        public void Test_ToString_UIGridNull_PropertyNull_UIColumnIDNull()
        {
            //---------------Set up test pack-------------------
            UIGridColumnInfo uiGridColumn = TestUtilsUIGridColumnInfo.CreateUnsavedValidUIColumn_WNullGrid_NullProperty
                ();
//            uiGridColumn.Property = null;
            uiGridColumn.UIPropID = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiGridColumn.UIGrid);
            Assert.IsNull(uiGridColumn.PropertyName);
            Assert.IsNull(uiGridColumn.UIPropID);
            //---------------Execute Test ----------------------
            string actualToString = uiGridColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-unnamed UIGridColumnInfo-", actualToString);
        }

        [Test]
        public void Test_IUIGridColumn_Editable_Get()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            ((UIGridColumnInfo)gridColumn).Editable = false;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool returnedEditable = gridColumn.Editable;
            //---------------Test Result -----------------------
            Assert.IsFalse(returnedEditable);

        }

        [Test]
        public void Test_IUIGridColumn_Editable_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            gridColumn.Editable = false;
            //---------------Test Result -----------------------
            bool returnedEditable = gridColumn.Editable;
            Assert.IsFalse(returnedEditable);
        }


        [Test]
        public void Test_IUIGridColumn_GetHeading()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string heading = TestUtilsShared.GetRandomString();
            ((UIGridColumnInfo)gridColumn).Heading = heading;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string returnedHeading = gridColumn.GetHeading();
            //---------------Test Result -----------------------
            Assert.AreEqual(heading, returnedHeading);
        }

        [Test]
        public void Test_IUIGridColumn_GetHeading_ClassDef()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string heading = TestUtilsShared.GetRandomString();
            ((UIGridColumnInfo)gridColumn).Heading = heading;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string returnedHeading = gridColumn.GetHeading(ClassDef.Get<UIGridColumnInfo>());
            //---------------Test Result -----------------------
            Assert.AreEqual(heading, returnedHeading);
        }

        [Test]
        public void Test_IUIGridColumn_Heading_Get()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string heading = TestUtilsShared.GetRandomString();
            ((UIGridColumnInfo)gridColumn).Heading = heading;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string returnedHeading = gridColumn.Heading;
            //---------------Test Result -----------------------
            Assert.AreEqual(heading, returnedHeading);
        }

        [Test]
        public void Test_IUIGridColumn_Heading_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string heading = TestUtilsShared.GetRandomString();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            gridColumn.Heading = heading;

            //---------------Test Result -----------------------
            string returnedHeading = gridColumn.Heading;
            Assert.AreEqual(heading, returnedHeading);
        }

        [Test]
        public void Test_IUIGridColumn_Width_Get()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            int width = TestUtilsShared.GetRandomInt();
            ((UIGridColumnInfo)gridColumn).Width = width;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            int returnedWidth = gridColumn.Width;
            //---------------Test Result -----------------------
            Assert.AreEqual(width, returnedWidth);
        }

        [Test]
        public void Test_IUIGridColumn_Width_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            int width = TestUtilsShared.GetRandomInt();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            gridColumn.Width = width;

            //---------------Test Result -----------------------
            int returnedWidth = gridColumn.Width;
            Assert.AreEqual(width, returnedWidth);
        }

        [Test]
        public void Test_IUIGridColumn_PropertyName_Get()
        {
            //---------------Set up test pack-------------------
            DMProperty property = TestUtilsShared.CreateUnsavedValidDMProperty();
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            ((UIGridColumnInfo)gridColumn).PropertyName = property.PropertyName;
            //---------------Assert Precondition----------------
            Assert.IsTrue(property.PropertyName.Length > 0);
            //---------------Execute Test ----------------------
            string returnedPropertyName = gridColumn.PropertyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(property.PropertyName, returnedPropertyName);
        }

        [Test]
        public void Test_IUIGridColumn_PropertyName_Get_NoPropertySet()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            //---------------Assert Precondition----------------
            Assert.IsNull(((UIGridColumnInfo)gridColumn).PropertyName);
            //---------------Execute Test ----------------------
            string returnedPropertyName = gridColumn.PropertyName;
            //---------------Test Result -----------------------
            Assert.IsNull(returnedPropertyName);
        }

        [Test]
        public void Test_IUIGridColumn_PropertyName_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string propertyName = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------
            Assert.IsNull(((UIGridColumnInfo)gridColumn).PropertyName);
            //---------------Execute Test ----------------------
            gridColumn.PropertyName = propertyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(propertyName, gridColumn.PropertyName);
            Assert.AreEqual(propertyName, ((UIGridColumnInfo)gridColumn).PropertyName);
        }


        [Test]
        public void Test_IUIGridColumn_GridControlAssemblyName_Get()
        {
            //---------------Set up test pack-------------------
            UIGridColumnControlType uiGridColumnControlType = TestUtilsShared.CreateUnsavedValidUIGridColumnControlTypeInfo();
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            ((UIGridColumnInfo)gridColumn).UIGridColumnControlType = uiGridColumnControlType;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(((UIGridColumnInfo)gridColumn).UIGridColumnControlType);
            //---------------Execute Test ----------------------
            string returnedGridControlAssemblyName = gridColumn.GridControlAssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(uiGridColumnControlType.AssemblyName, returnedGridControlAssemblyName);
        }

        [Test]
        public void Test_IUIGridColumn_GridControlAssemblyName_Get_NoUIGridColumnControlType()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            //---------------Assert Precondition----------------
            Assert.IsNull(((UIGridColumnInfo)gridColumn).UIGridColumnControlType);
            //---------------Execute Test ----------------------
            string returnedGridControlAssemblyName = gridColumn.GridControlAssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", returnedGridControlAssemblyName);
        }

        [Test]
        public void Test_IUIGridColumn_GridControlAssemblyName_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            //---------------Assert Precondition----------------
            Assert.IsNull(((UIGridColumnInfo)gridColumn).UIGridColumnControlType);
            //---------------Execute Test ----------------------
            try
            {
                gridColumn.GridControlAssemblyName = TestUtilsShared.GetRandomString();
                Assert.Fail("Expected to throw an NotImplementedException");
            }
            //---------------Test Result -----------------------
            catch (NotImplementedException ex)
            {
                StringAssert.Contains("This should be set when the UIGridColumnControlType is set for the UIGridColumnInfo.", ex.Message);
            }
        }

        [Test]
        public void Test_IUIGridColumn_GridControlTypeName_Get()
        {
            //---------------Set up test pack-------------------
            UIGridColumnControlType uiGridColumnControlType = TestUtilsShared.CreateUnsavedValidUIGridColumnControlTypeInfo();
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            ((UIGridColumnInfo)gridColumn).UIGridColumnControlType = uiGridColumnControlType;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(((UIGridColumnInfo)gridColumn).UIGridColumnControlType);
            //---------------Execute Test ----------------------
            string returnedGridControlTypeName = gridColumn.GridControlTypeName;
            //---------------Test Result -----------------------
            Assert.AreEqual(uiGridColumnControlType.TypeName, returnedGridControlTypeName);
        }

        [Test]
        public void Test_IUIGridColumn_GridControlTypeName_Get_NoUIGridColumnControlType()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            //---------------Assert Precondition----------------
            Assert.IsNull(((UIGridColumnInfo)gridColumn).UIGridColumnControlType);
            //---------------Execute Test ----------------------
            string returnedGridControlTypeName = gridColumn.GridControlTypeName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", returnedGridControlTypeName);
        }

        [Test]
        public void Test_IUIGridColumn_GridControlTypeName_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            //---------------Assert Precondition----------------
            Assert.IsNull(((UIGridColumnInfo)gridColumn).UIGridColumnControlType);
            //---------------Execute Test ----------------------
            try
            {
                gridColumn.GridControlTypeName = TestUtilsShared.GetRandomString();
                Assert.Fail("Expected to throw an NotImplementedException");
            }
            //---------------Test Result -----------------------
            catch (NotImplementedException ex)
            {
                StringAssert.Contains("This should be set when the UIGridColumnControlType is set for the UIGridColumnInfo.", ex.Message);
            }
        }

        [Test]
        public void Test_IUIGridColumn_Alignment_Get()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string alignment = PropAlignment.centre.ToString();
            ((UIGridColumnInfo)gridColumn).Alignment = alignment;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            PropAlignment returnedAlignment = gridColumn.Alignment;
            //---------------Test Result -----------------------
            Assert.AreEqual(returnedAlignment.ToString(), alignment);
       }


        [Test]
        public void Test_IUIGridColumn_Alignment_Set()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            gridColumn.Alignment = PropAlignment.right;

            //---------------Test Result -----------------------
            PropAlignment propAlignment = gridColumn.Alignment;
            Assert.AreEqual(PropAlignment.right, propAlignment);
       }

        [Test]
        public void Test_IUIGridColumn_Parameters_NoParameters()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Hashtable returnedParameters = gridColumn.Parameters;
            //---------------Test Result -----------------------
            BusinessObjectCollection<UIParameter> parameters = ((UIGridColumnInfo)gridColumn).UIParameters;
            Assert.AreEqual(parameters.Count, returnedParameters.Count);

            foreach (UIParameter parameter in parameters)
            {
                Assert.IsTrue(returnedParameters.ContainsKey(parameter.Name));
                Assert.IsTrue(returnedParameters.ContainsValue(parameter.Value));
            }
        }

        [Test]
        public void Test_IUIGridColumn_Parameters()
        {
            //---------------Set up test pack-------------------
            UIGridColumnInfo columnInfo = new UIGridColumnInfo();
            TestUtilsShared.CreateUnsavedValidUIParameterInfo(columnInfo);
            IUIGridColumn gridColumn = columnInfo;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Hashtable returnedParameters = gridColumn.Parameters;

            //---------------Test Result -----------------------
            BusinessObjectCollection<UIParameter> parameters = ((UIGridColumnInfo)gridColumn).UIParameters;
            Assert.AreEqual(parameters.Count, returnedParameters.Count);

            foreach (UIParameter parameter in parameters)
            {
                Assert.IsTrue(returnedParameters.ContainsKey(parameter.Name));
                Assert.IsTrue(returnedParameters.ContainsValue(parameter.Value));
            }
        }

        [Test]
        public void Test_IUIGridColumn_GetParameterValue()
        {
            //---------------Set up test pack-------------------
            UIGridColumnInfo columnInfo = new UIGridColumnInfo();
            UIParameter uiParameter = TestUtilsShared.CreateUnsavedValidUIParameterInfo(columnInfo);
            IUIGridColumn gridColumn = columnInfo;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            object returnedParameterValue = gridColumn.GetParameterValue(uiParameter.Name);
            //---------------Test Result -----------------------
            Assert.AreEqual(uiParameter.Value, returnedParameterValue);
        }

        [Test]
        public void Test_IUIGridColumn_GetParameterValue_ParameterDoesNotExist()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string parameterName = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                gridColumn.GetParameterValue(parameterName);
                Assert.Fail("Expected to throw an ArgumentException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentException ex)
            {
                StringAssert.Contains("parameterName", ex.ParamName);
                StringAssert.Contains("There is no parameter with the name '" + parameterName + "' for the UIGridColumn", ex.Message);
            }
        }

        [Test]
        public void Test_IUIGridColumn_GetParameterValue_NoParameter()
        {
            //---------------Set up test pack-------------------
            IUIGridColumn gridColumn = new UIGridColumnInfo();
            string parameterName = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                gridColumn.GetParameterValue(null);
                Assert.Fail("Expected to throw an ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("parameterName", ex.ParamName);
                StringAssert.Contains("Value cannot be null", ex.Message);
            }
        }


        //[Test]
        //public void Test_IUIGridColumn_GridControlType_Get()
        //{
        //    //---------------Set up test pack-------------------

        //    UIGridColumnInfo columnInfo = TestUtilsShared.CreateUnsavedValidUIColumnInfo();
        //    DMSolution solution = columnInfo.UIGrid.UIView.Class.Solution;
        //    UIGridColumnControlType uiGridColumnControlType = solution.GetGridColumnControlType("System.Windows.Forms",
        //                                                                     "DataGridViewTextBoxColumn");
        //    columnInfo.UIGridColumnControlType = uiGridColumnControlType;
        //    IUIGridColumn gridColumn = columnInfo;

        //    //---------------Assert Precondition----------------
        //    Assert.IsNotNull(columnInfo.UIGridColumnControlType);
        //    //---------------Execute Test ----------------------
        //    Type returnedGridControlType = gridColumn.GridControlType;
        //    //---------------Test Result -----------------------
        //    Assert.AreEqual(uiGridColumnControlType.AssemblyName + "." + uiGridColumnControlType.TypeName, returnedGridControlType.ToString());
        //}

        //[Test]
        //public void Test_IUIGridColumn_GridControlType_Get_NoControlType()
        //{
        //    //---------------Set up test pack-------------------
        //    UIGridColumnInfo columnInfo = new UIGridColumnInfo();
        //    IUIGridColumn gridColumn = columnInfo;

        //    //---------------Assert Precondition----------------
        //    Assert.IsNull(columnInfo.UIGridColumnControlType);
        //    //---------------Execute Test ----------------------
        //    Type returnedGridControlType = gridColumn.GridControlType;
        //    //---------------Test Result -----------------------
        //    Assert.IsNull(returnedGridControlType);
        //}

        //[Test]
        //public void Test_IUIGridColumn_GridControlType_Set()
        //{
        //    //---------------Set up test pack-------------------
        //    IUIGridColumn gridColumn = new UIGridColumnInfo();

        //    //---------------Assert Precondition----------------

        //    //---------------Execute Test ----------------------
        //    try
        //    {
        //        gridColumn.GridControlType = TypeLoader.LoadType("System.Windows.Forms", "DataGridViewTextBoxColumn");
        //        Assert.Fail("Expected to throw an ArgumentNullException");
        //    }
        //    //---------------Test Result -----------------------
        //    catch (NotImplementedException ex)
        //    {
        //        StringAssert.Contains("Please set this via the UIGridColumnControlType relationship.", ex.Message);
        //    }
        //}
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            UIGridInfo uiGridInfo = new UIGridInfo();
            UIGridColumnInfo uiGridColumnInfo = new UIGridColumnInfo();
            uiGridInfo.UIColumns.Add(uiGridColumnInfo);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelElement)uiGridColumnInfo).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(uiGridInfo, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelElement prop = new UIGridColumnInfo();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                prop.Parent = new UIGridInfo();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the UIGridColumnInfo by setting the related UIGrid object", exceptionThrown.Message);
        }


    }
}